<?php
namespace AuctionCore\Account;


/**
* 帐户组 测试类
* @author       爱民
*/
class UserTest extends \PHPUnit_Framework_TestCase
{

	public function testFrountUserCreate(){
		//创建前台用户	[用户名，密码,昵称,手机号]
		$user_info = array();
		$user_info['user_name'] = 'unit_test';
		$user_info['passwd'] = 'cccccc';
		$user_info['nick_name'] = 'test_nick_name';
		$user_info['sms_mobile'] = '13552528384';
		$user_info['pwd_mobile'] = '13552528384';
		$user_id = \AuctionCore\Account\FrontUser::create($user_info);
		$this->assertTrue(intval($user_id)>0);

		$fu = new \AuctionCore\Account\FrontUser('unit_test');
		//密码正确
		$info = $fu->check_pwd('cccccc');		
		$this->assertEquals('array',gettype($info));
		//密码错误
		$info = $fu->check_pwd('testa');		
		$this->assertTrue($info==false);	
	}

	public function testGetUserInfo(){	
		//获取用户信息	
		$fu = new \AuctionCore\Account\FrontUser('unit_test'); //使用用户名
		$info = $fu->user_info();
		$this->assertTrue(intval($info['uid'])>0);
		$fu = new \AuctionCore\Account\FrontUser($info['uid']);//使用uid
		$info = $fu->user_info();
		$this->assertTrue(intval($info['uid'])>0);
	}

	public function testChangePassword(){	
		//修改密码
		$fu = new \AuctionCore\Account\FrontUser('unit_test');
		$ok = $fu->change_password('test');
		$this->assertTrue(intval($ok)>0);

		$fu = new \AuctionCore\Account\FrontUser('unit_test');
		$info = $fu->user_info();
		$this->assertEquals($info['passwd'],'098f6bcd4621d373cade4e832627b4f6');

	}

	public function testChangePwdMobile(){
		//修改手机号
		$fu = new \AuctionCore\Account\FrontUser('unit_test');
		$fu->change_sms_mobile('13000888888');
		$fu->change_pwd_mobile('13000888881');

		$info = $fu->user_info();
		$this->assertEquals($info['sms_mobile'],'13000888888'); 
		$this->assertEquals($info['pwd_mobile'],'13000888881');

	}

	public function testUserSetGroup(){	
		$group_info = array();
		$group_info['title'] = 'test';
		$group_info['status'] = 1;
		$group_info['rules'] = '';
		$group_info['remark'] = '前台车主用户帐号组';	

		//创建前台用户组
		$f_group =	new \AuctionCore\Account\Group();		 	
		$insertID = $f_group->create($group_info);
		$this->assertTrue(is_numeric($insertID));

		$fu = new \AuctionCore\Account\FrontUser('unit_test');
		$fu->set_group($insertID); //添加用户属组
		$groups = $fu->get_groups();//获取用户属组权限
		$this->assertTrue(count($groups)>0)	;
		$ok = $fu->exgraft_group($insertID);//移出组		
		$this->assertTrue(intval($ok)>0);

		//删除前台用户组;
		$f_group =	new \AuctionCore\Account\Group();		 	
		$ok = $f_group->del($insertID);
		$this->assertEquals(1,$ok);
	}

	public function testRemoveUser(){		
		//删除用户
		$ok = \AuctionCore\Account\FrontUser::remove('unit_test');
		$this->assertTrue($ok==1);
	}


	public function testChangeavator(){
		//更新头像
		$fu = new \AuctionCore\Account\FrontUser('test2');
		$ok = $fu->change_avatar("http://clcw.oss-cn-beijing.aliyuncs.com/head/2015-11-09/ce44/1e74/c54fc59a-356c-75a0-7269-fd7b147dc131.jpg");
	}

	

}

?>